package com.darwin.darwinDll.analyze
{
	import com.darwin.darwinDll.core.DllItem;
	
	import flash.utils.Dictionary;

	/**
	 *  解析器字典
	 * @author vanCopper
	 * 
	 */	
	public class AnalyzeDictionary
	{
		private static var instance:AnalyzeDictionary;
		private var analyzeDic:Dictionary;
		
		public function AnalyzeDictionary()
		{
			if(instance==null)
			{
				analyzeDic = new Dictionary();
				analyzeDic[DllItem.TYPE_IMG] = ImgAnalyze;
				analyzeDic[DllItem.TYPE_BIN] = BinAnalyze;
				analyzeDic[DllItem.TYPE_DDD] = DDDAnalyze;
				analyzeDic[DllItem.TYPE_JSON] = JsonAnalyze;
				analyzeDic[DllItem.TYPE_XML] = XmlAnalyze;
				analyzeDic[DllItem.TYPE_SWF] = SwfAnalyze;
				analyzeDic[DllItem.TYPE_DAR] = DarAnalyze;
				analyzeDic[DllItem.TYPE_DARX] = DarXAnalyze;
			}else{throw new Error("实例AnalyzeDictionary出错");}
		}
		
		public static function getInstance():AnalyzeDictionary
		{
			if(!instance)
			{
				instance = new AnalyzeDictionary();
			}
			return instance;
		}
		
		/**
		 *注册一个解析器 
		 * @param key
		 * @param analyzeClass
		 * 
		 */		
		public function registerAnalyze(key:String,analyzeClass:Class):void
		{
			if(!analyzeDic[key])
			{
				analyzeDic[key] = analyzeClass;
			}
		}
		
		/**
		 *获取已有解析器 
		 * @param key
		 * @return 
		 * 
		 */		
		public function getAnalyze(key:String):IAnalyze
		{
			if(analyzeDic[key] is Class)
			{
				analyzeDic[key] = new (analyzeDic[key] as Class)();
			}
			return analyzeDic[key];
		}
	}
}